package com.sg.business.commons.url;

import java.util.HashMap;
import java.util.Map;

import com.mobnut.commons.Commons;
import com.mobnut.db.file.RemoteFile;
import com.sg.business.model.Document;
import com.sg.widgets.commons.model.OpenURLProvider;

public class OpenGenericDocumentURL extends OpenURLProvider {

	@Override
	public Map<String, String> getParameters(Object data,
			RemoteFile remoteFile) {
		if (data instanceof Document) {
			Document doc = (Document) data;

			Map<String, String> result = new HashMap<String, String>();
			result.put(Commons.SERVLET_OPEN_COMMENT_PARA_DB, doc.getDbName());
			result.put(Commons.SERVLET_OPEN_COMMENT_PARA_COL,
					doc.getCollectionName());
			result.put(Commons.SERVLET_OPEN_COMMENT_PARA_FIELD,
					Document.F_COMMENTS);
			result.put(Commons.SERVLET_OPEN_COMMENT_PARA_ID, doc.get_id()
					.toString());
			if (doc.isHistoryVersion()) {
				result.put(Commons.SERVLET_OPEN_COMMENT_QUERY_PARA_FIELD,
						Document.F_VERSIONHISTORY + "._id");
				result.put(Commons.SERVLET_OPEN_COMMENT_QUERY_PARA_DATA_FIELD,
						Document.F_VERSIONHISTORY + "." + Document.F_COMMENTS);
				result.put(Commons.SERVLET_OPEN_COMMENT_QUERY_PARA_CHILD_FIELD,
						Document.F_VERSIONHISTORY);
				result.put(Commons.SERVLET_OPEN_COMMENT_QUERY_PARA_CHILD_KEY,
						Document.F__ID);
				result.put(Commons.SERVLET_OPEN_COMMENT_QUERY_PARA_CHILD_ID,
						doc.get_id().toString());
				result.put(Commons.SERVLET_CAN_SUBMIT_COMMENT,
						Boolean.FALSE.toString());
			}
			return result;

		}
		return null;
	}

}
